#include <stdio.h>
#include <stdlib.h>
#define SIZE 5
typedef struct {
    int* data;
    int front;
    int rear;
    int capacity;
} CircularQueue;

CircularQueue* createQueue() {
    CircularQueue* queue = (CircularQueue*)malloc(sizeof(CircularQueue));
    queue->data = (int*)malloc(sizeof(int) * SIZE);
    queue->front = -1;
    queue->rear = -1;
    queue->capacity = SIZE;
    return queue;
}

int isEmpty(CircularQueue* queue) {
    return (queue->front == -1);
}

int isFull(CircularQueue* queue) {
    return ((queue->rear + 1) % queue->capacity == queue->front);
}

void enqueue(CircularQueue* queue, int item) {
    if (isFull(queue)) {
        printf("Queue is full!\n");
        return;
    }
    if (isEmpty(queue)) {
        queue->front = 0;
    }
    queue->rear = (queue->rear + 1) % queue->capacity;
    queue->data[queue->rear] = item;
    printf("%d enqueued to queue.\n", item);
}

int dequeue(CircularQueue* queue) {
    if (isEmpty(queue)) {
        printf("Queue is empty!\n");
        return -1;
    }
    int item = queue->data[queue->front];
    if (queue->front == queue->rear) {
        queue->front = -1;
        queue->rear = -1;
    } else {
        queue->front = (queue->front + 1) % queue->capacity;
    }
    printf("%d dequeued from queue.\n", item);
    return item;
}

int main() {
    CircularQueue* queue = createQueue();

    enqueue(queue, 1);
    enqueue(queue, 2);
    enqueue(queue, 3);
    enqueue(queue, 4);
    enqueue(queue, 5);
    enqueue(queue, 6);  // 队列已满，无法入队

    dequeue(queue);
    dequeue(queue);
    dequeue(queue);
    dequeue(queue);
    dequeue(queue);
    dequeue(queue);  // 队列已空，无法出队

    free(queue->data);
    free(queue);
    return 0;
}

